<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件向父组件传递数据</title>
</head>
<body>
<div id="app">
    <!-- 接收自定义事件 -->
    <cpn v-on:btnclicked="clicked"></cpn>
</div>

<template id="cpn">
    <button v-on:click="btnClicked">发送</button>
</template>

<script type="module">
    import {createApp} from "../../../../js/vue.esm-browser.js";
    import {defineComponent, defineEmits} from "../../../../js/vue.esm-browser.js";


    let cpn = defineComponent(
        {
            template: "#cpn",
            emits: ["btnclicked"],

            setup(props, context) {
                function btnClicked() {
                    console.log("点击了按钮");
                    // 发送自定义事件
                    context.emit("btnclicked")
                }

                return {
                    btnClicked,
                }
            }
        }
    );

    let app = createApp({
        setup() {
            function clicked() {
                console.log("接收到了子组件传递过来的消息");
            }

            return {clicked}
        },
        components: {
            cpn,
        }
    })

    app.mount("#app")
</script>
</body>
</html>